package com.dlc.shop.systemtest.data.maketing;

import cn.hutool.core.date.DateUtil;
import com.dlc.shop.bean.model.Giveaway;
import com.dlc.shop.bean.model.GiveawayProd;
import com.dlc.shop.bean.model.Product;
import com.dlc.shop.systemtest.api.amount.ProductApi;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lpj
 */
public class GiveawayData {

    /**
     * 赠品数据
     */
    public static Giveaway getGiveaway(Long mainProductId, List<Long> giveawayProdIds) {
        Giveaway giveaway = new Giveaway();
        giveaway.setProdId(mainProductId);
        giveaway.setName("赠品名称");
        giveaway.setStatus(1);
        giveaway.setBuyNum(3);
        giveaway.setStartTime(DateUtil.parse("2023-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        giveaway.setEndTime(DateUtil.parse("2025-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));

        giveaway.setGiveawayProds(getGiveawayProd(giveawayProdIds));

        return giveaway;
    }

    /**
     * 赠品搭配商品数据
     */
    public static List<GiveawayProd> getGiveawayProd(List<Long> giveawayProdIds) {
        List<GiveawayProd> giveawayProds = new ArrayList<>();
        for (Long giveawayProdId : giveawayProdIds) {
            GiveawayProd giveawayProd = new GiveawayProd();
            Product product = ProductApi.getProductInfo(giveawayProdId);
            giveawayProd.setGiveawayNum(1);
            giveawayProd.setRefundPrice(11.0);
            giveawayProd.setProdId(product.getProdId());
            giveawayProd.setProdName(product.getProdName());
            giveawayProd.setSkuId(product.getSkuList().get(0).getSkuId());
            giveawayProd.setPrice(product.getSkuList().get(0).getPrice());
            giveawayProd.setSkuName(product.getSkuList().get(0).getSkuName());
            giveawayProds.add(giveawayProd);
        }

        return giveawayProds;
    }
}
